const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader')
const AutoImport = require('unplugin-auto-import/webpack').default
const Components = require('unplugin-vue-components/webpack').default
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const webpackBundleAnalyzer = require('webpack-bundle-analyzer')
const WebpackBarProgressPlugin = require('webpackbar')

console.log(webpackBundleAnalyzer , 9999)


module.exports = {
    entry: './src/main.js',
    output: {
        filename: 'bundle[hash:8].js',
        path: path.resolve(__dirname, 'dist'),
        clean: true
    },
    module: {
        rules: [
            {
                test: /\.less|css$/i,
                use: [
                    'style-loader',
                    'css-loader',
                    'postcss-loader',
                    'less-loader',
                ],
            },

            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.js$/, // 匹配所有的.js文件
                exclude: /node_modules/, // 排除node_modules目录
                use: 'babel-loader'
            },
            {
                test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
                type: 'asset/resource',
            },

        ]
    },
    mode: 'development',
    plugins: [
        new HtmlWebpackPlugin({ template: './public/index.html' }),
        new VueLoaderPlugin(),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
        new webpackBundleAnalyzer.BundleAnalyzerPlugin(),
        new WebpackBarProgressPlugin()
    ],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src')
        },
        extensions: ['.js', '.vue', '.json', '.css'],
    },
    optimization: {},
    devServer: {
        static: {
            directory: path.join(__dirname, 'public'),
        },
        compress: true,
        port: 9000,
    },
};
